package com.ruoyi.miaomiao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.miaomiao.domain.Trolley;
import com.ruoyi.miaomiao.service.ITrolleyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购物车管理Controller
 * 
 * @author ruoyi
 * @date 2022-07-26
 */
@RestController
@RequestMapping("/miaomiao/trolley")
public class TrolleyController extends BaseController
{
    @Autowired
    private ITrolleyService trolleyService;

    /**
     * 查询购物车管理列表
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:trolley:list')")
    @GetMapping("/list")
    public TableDataInfo list(Trolley trolley)
    {
        startPage();
        List<Trolley> list = trolleyService.selectTrolleyList(trolley);
        return getDataTable(list);
    }

    /**
     * 导出购物车管理列表
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:trolley:export')")
    @Log(title = "购物车管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Trolley trolley)
    {
        List<Trolley> list = trolleyService.selectTrolleyList(trolley);
        ExcelUtil<Trolley> util = new ExcelUtil<Trolley>(Trolley.class);
        util.exportExcel(response, list, "购物车管理数据");
    }

    /**
     * 获取购物车管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:trolley:query')")
    @GetMapping(value = "/{trolleyId}")
    public AjaxResult getInfo(@PathVariable("trolleyId") Long trolleyId)
    {
        return AjaxResult.success(trolleyService.selectTrolleyByTrolleyId(trolleyId));
    }

    /**
     * 新增购物车管理
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:trolley:add')")
    @Log(title = "购物车管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Trolley trolley)
    {
        return toAjax(trolleyService.insertTrolley(trolley));
    }

    /**
     * 修改购物车管理
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:trolley:edit')")
    @Log(title = "购物车管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Trolley trolley)
    {
        return toAjax(trolleyService.updateTrolley(trolley));
    }

    /**
     * 删除购物车管理
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:trolley:remove')")
    @Log(title = "购物车管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trolleyIds}")
    public AjaxResult remove(@PathVariable Long[] trolleyIds)
    {
        return toAjax(trolleyService.deleteTrolleyByTrolleyIds(trolleyIds));
    }
}
